<?php

/**
 * 数据表操作
 * @author Shaun
 */

namespace Member\Table;

use Utility\ServiceLocator\ServiceLocator;
use Zend\Db\TableGateway\TableGateway;
// 日志
use Utility\Log\Logger;
use Zend\Db\Sql\Select;
use Authority\Authority\Authority;

class MemberTable {

    protected $tableGateway;

    public function __construct(TableGateway $tableGateway) {
        $this->tableGateway = $tableGateway;
    }

    /**
     * 渲染出类的相关信息
     * @return \Zend\Db\TableGateway\TableGateway
     */
    public function getMemberGateway() {
        return $this->tableGateway;
    }

    //获取所有信息
    /**
     * 渲染出类的相关信息
     * @return \Member\Model\MemberModel
     */
    public function selectAll() {
        try {
            $result = $this->getMemberGateway()->select(array("id" => '1'));
            return $result;
        } catch (Exception $exc) {
            Logger::getLogger()->warn(__CLASS__ . "::" . __FUNCTION__ . "  [ " . $exc->getPrevious() . " ]");
            return false;
        }
    }

    //新增
    /**
     * 渲染出类的相关信息
     * @return \Member\Model\MemberModel
     */
    public function insertInto($data) {
        try {
            $result = $this->getMemberGateway()->insert($data);
            return $result;
        } catch (Exception $exc) {
            Logger::getLogger()->warn(__CLASS__ . "::" . __FUNCTION__ . "  [ " . $exc->getPrevious() . " ]");
            return false;
        }
    }

    //修改
    /**
     * 渲染出类的相关信息
     * @return \Member\Model\MemberModel
     */
    public function editByCond($data, $where) {
        try {
            $result = $this->getMemberGateway()->update($data, $where);
            return $result;
        } catch (Exception $exc) {
            Logger::getLogger()->warn(__CLASS__ . "::" . __FUNCTION__ . "  [ " . $exc->getPrevious() . " ]");
            return false;
        }
    }

    //获取某条件下的信息
    /**
     * 渲染出类的相关信息
     * @return \Member\Model\MemberModel
     */
    public function selectByCond($where) {
        try {
            $result = $this->getMemberGateway()->select($where);
            return $result;
        } catch (Exception $exc) {
            Logger::getLogger()->warn(__CLASS__ . "::" . __FUNCTION__ . "  [ " . $exc->getPrevious() . " ]");
            return false;
        }
    }

}
